// ==UserScript==
// @name            TW-Fullscreen addon
// @namespace       http://pl-the-west.googlecode.com/svn/trunk/pl-the-west/test/tw_fullscreen_addon.user.js
// @description     Zmiana wyglądu TW. wersja 1.0 beta
// @author          Dariusz Szyndler (Darius II)
// @website         http://dariuszszyndler.pl/wp/
// @include         http://*.the-west.*/game.php*
// @include         http://*.the-west.*/forum.php*
// @include        	http://*.the-west.net/*
// @version         1.0 beta
// ==/UserScript==

(function(f){var d=document,s=d.createElement('script');s.setAttribute('type','application/javascript');s.textContent = '('+f.toString()+')()';(d.body||d.head||d.documentElement).appendChild(s);s.parentNode.removeChild(s)})(function(){

	window.addEvent('domready', function(){
		// ustawienia wstępne
		var werTWFS = '1.0 beta';
		var dateTWFS = '08-07-12r'
		var werTW = TheWestApi.version; // wersja TW
		
		var base_img = 'http://pl-the-west.googlecode.com/svn/trunk/pl-the-west/images/'; // sciezka do grafiki
		
		var sma_fort_img = base_img + "Forty/maly.png"; // maly fort
		var med_fort_img = base_img + "Forty/sredni.png"; // sredni fort
		var big_fort_img = base_img + "Forty/duzy.png"; // duzy fort
		var ico_fort_img = base_img + "Forty/ico_fort.png"; // ikonka fortow
		var ico_inw_twdb = base_img + "ico_twdbinfo.png"; // ikonka eksportu tw-db
		var ico_inw_wf = base_img + "ico_westforts.png"; // ikonka eksportu westforts
		var sma_fort_ico = base_img + "Forty/ico_maly.png"; // maly fort ikonka
		var med_fort_ico = base_img + "Forty/ico_sred.png"; // sredni fort ikonka
		var big_fort_ico = base_img + "Forty/ico_duzy.png"; // duzy fort ikonka
		var small_border_img = base_img + "borders_window.png"; // ramka dla małych okienek
		var help_wf = '<div>Proszę otworzyć raport z bitwy którą, chcemy wyeksportować do westforts i poczekać aż się otworzy nowe okno<br />z wyeksportowanymi danymi. To okno można już zamknąć.</div>';
		// end ustawienia wstępne
		
		// ukrywane menu
		$('left_menu').setStyles({'height':'auto','left':'-123px','background-position':'119px 0','clip':'rect(auto, auto, auto, 100px)'}).addEvents({mouseover:function(){$('left_menu').setStyles({'left':'-20px','background-position':'16px 0','clip':'rect(auto, auto, auto, 0px)'});},mouseout:function(){$('left_menu').setStyles({'left':'-123px','background-position':'119px 0','clip':'rect(auto, auto, auto, 100px)'});}});
		right_menu_bgpov = $('right_menu').getStyle('background-position').toInt()-9; // -9
		right_menu_bgpou = right_menu_bgpov-99; //95
		$('right_menu').setStyles({'height':'auto','right':'-119px','background-position':right_menu_bgpou+'px 0','clip':'rect(auto, 28px, auto, auto)'}).addEvents({mouseover:function(){$('right_menu').setStyles({'right':'-20px','clip':'rect(auto, 127px, auto, auto)', 'background-position':right_menu_bgpov+'px 0'});},mouseout:function(){$('right_menu').setStyles({'right':'-119px','clip':'rect(auto, 28px, auto, auto)', 'background-position':right_menu_bgpou+'px 0'});}});
		// end ukrywane menu
		//$$(['workbar_left','workbar_right','border_cap','footer_menu_left','footer_menu_right','head_title','head_background','.workbar_top']).setStyle('background','transparent');
		//var dis_bg_cl = [];
		//new Array('', 'workbar_right .workbar_top', '.bottomleftcurve', '.bottomrightcurve', 'shadow_left_wing', 'shadow_right_wing', 'shadow_top, shadow_bottom', 'workbar_right.wb_premium .workbar_top');
		//for(var i = 0; i < dis_bg_id.length; i++){ if (dis_bg_id[i].length) { $(dis_bg_id[i]).setStyle('background','transparent'); }}
		//for(var i = 0; i < dis_bg_cl.length; i++){ if (dis_bg_cl[i].length) { $$(dis_bg_cl[i]).setStyle('background','transparent'); }}
		
		// wyłączenie elementów
		$$(['border_cap','shadow_top','shadow_left_top','shadow_right_top','shadow_left_wing','shadow_right_wing','shadow_right_wing','shadow_left_wing_bottom','shadow_right_wing_bottom','head_title','abdorment_left','abdorment_right','wb_buy_pa']).setStyle('display','none');
		// end wyłączenie elementów
		
		// ukrycie tła
		$$(['workbar_left','workbar_right']).setStyle('background','transparent');
		// end ukrycie tła
		//$$(['shadow_top','abdorment_left','abdorment_right','shadow_left_wing','shadow_right_wing','shadow_left_top','shadow_right_top','shadow_left_wing_bottom','shadow_right_wing_bottom','shadow_right_wing_bottom','shadow_left_side','shadow_right_side','shadow_left_corner','shadow_right_corner','wb_buy_pa']).setStyle('display','none');
		// end wyłączenie elementów
		
		// zmiana pozycji elementów
		$('main_sizer').setStyles({'padding-top':'70px'});
		$('head_background').setStyles({'margin-left':'0px','margin-right':'0px'});
		$('character_info').setStyles({'left':'-89px','z-index':'4','margin':'0 0 0 24px'});
		$('avatar').setStyles({'top':'-2px'});
		var head = $$(['avatar_picture','level_box','character_name','health_bar','energy_bar','experience_bar','character_money']);
		jQuery.each(head, function() {
			head_top = $(this).getStyle('top').toInt()-5;
			$(this).setStyle('top',head_top+'px');
		});
		character_money_mr = $('character_money').getStyle('margin-right').toInt()-195;
		$('character_money').setStyles({'margin-right':character_money_mr+'px'});
		$('main_container').setStyles({'margin-left':'15px','margin-right':'19px'});
		$('main_container_border_left').setStyles({'left':'15px'});
		$('main_container_border_right').setStyles({'right':'19px'});
		$('current_task_box').setStyles({'z-index':'5','top':'85px'});
		$('main_container_position').setStyle('top','150px');
		jQuery('#map_scroll_top').attr('id','mapscrolltop');
		jQuery('#mapscrolltop').css('cssText', 'top:-70px;left:260px;background:url("http://www.the-west.pl/images/main/map_arrows.png") 0px 20px;');
		jQuery('#map_scroll_right').attr('id','mapscrollright');
		jQuery('#mapscrollright').css('cssText', 'top:-50px;left:280px;background:url("http://www.the-west.pl/images/main/map_arrows.png") 40px 0px;');
		jQuery('#map_scroll_bottom').attr('id','mapscrollbottom');
		jQuery('#mapscrollbottom').css('cssText', 'top:-30px;left:260px;background:url("http://www.the-west.pl/images/main/map_arrows.png") 20px 40px;');
		jQuery('#map_scroll_left').attr('id','mapscrollleft');
		jQuery('#mapscrollleft').css('cssText', 'top:-50px;left:240px;background:url("http://www.the-west.pl/images/main/map_arrows.png") 20px 20px;');
		map_border_bottom_top = $('map_border_bottom').getStyle('top').toInt()+150;
		$('map_border_bottom_sizer').setStyle('top',map_border_bottom_top+'px');
		jQuery('#map_border_bottom_sizer').mouseup(function() {
			jQuery('#map_border_bottom_sizer').css({'margin-top':'18px'});
		});
		$('buffbar').setStyles({'top':'-65px','right':'170px','width':'auto'});
		$$('.chat_text ').setStyles({'font-size':'1.2em'});
		// end zmiana pozycji elementów
		
		// zmiana pozycji elementów
		/*$('main_sizer').setStyles({'padding-top':'60px'});
		if($('bugreport-cont')) $('bugreport-cont').setStyles({'top':'0px'});*/
		
		
		//
		/*
		
		
		$('main_container_position').setStyles({'top':'53px'});
		
		div_shopUP = new Element('div',{'styles':{'position':'absolute','left':'650px','top':'0px','z-index':'10'},'id':'div_shopUP'});
		var a_shopUP = new Element('a',{'id':'a_shopUP','onclick':'javascript:UPShopWindow.open();'});
		var shopUP = new Element('img',{'id':'shopUP','src':base_img+'/shop.png'});
		a_shopUP.inject(div_shopUP);
		shopUP.inject(a_shopUP);
		div_shopUP.injectBefore('head_container');*/
		
		// gorne menu
		demp = new Element('div',{'styles':{'position':'fixed','right':'0px','top':'0px','z-index':'10','width':'auto','height':'60px','border':'0px','display':'block','background':'url('+base_img+'bg_pm.png) no-repeat 0px bottom'},'id':'p_ext_menu'});
		deml = new Element('div',{'styles':{'position':'fixed','left':'0px','top':'0px','z-index':'10','width':'auto','height':'70px','border':'0px','display':'block','background':'url('+base_img+'bg_lm.png) no-repeat right bottom','padding-right':'15px'},'id':'l_ext_menu'});
		dmlb = new Element ('div',{'styles':{'display':'block','position':'relative','width':'50px','height':'20px','top':'60px','background':'url('+base_img+'bg_bl.png) no-repeat','right':'40px','float':'right','margin-right':'-50px'},'id':'lbmb'});
		
		dmi = new Element('div',{'styles':{'display':'none','width':'auto','height':'80px','padding-left':'15px'},'id':'lim'});
		dme = new Element('div',{'styles':{'display':'none','width':'auto','height':'80px','padding-left':'15px'},'id':'lem'});
		dmb = new Element('div',{'styles':{'display':'block','width':'auto','height':'80px','padding-left':'15px'},'id':'lbm'});
		dmpb = new Element ('div',{'styles':{'display':'block','position':'relative','width':'50px','height':'20px','float':'left','top':'-30px','left':'0px','background':'url('+base_img+'bg_bp.png) no-repeat'},'id':'pbmb'});
		
		demp.injectBefore('head_container');
		deml.injectBefore('head_container');
		
		l_praca = jQuery('#workbar_left');
		p_praca = jQuery('#workbar_right');
		
		jQuery('#p_ext_menu').append(dmi).append(dme).append(dmb).append(dmpb);
		jQuery('#l_ext_menu').append(dmlb).append(l_praca).append(p_praca).append(dmlb);
		
		hide = function (warst){
		if (warst == 'lim') { $('lim').setStyle('display','block');$('lem').setStyle('display','none');$('lbm').setStyle('display','none');};
		if (warst == 'lem') { $('lim').setStyle('display','none');$('lem').setStyle('display','block');$('lbm').setStyle('display','none');};
		if (warst == 'lbm') { $('lim').setStyle('display','none');$('lem').setStyle('display','none');$('lbm').setStyle('display','block');};
		};
		
		forty = function (fort){
		if (fort == 'maly') {
			wman.open('map_sma nominimize noreload').addTab('Mały fort').setMiniTitle('mały fort').setResizeable('on');
			jQuery('.map_sma .tw2gui_window_content_pane').append('<img src="'+sma_fort_img+'" />');
			jQuery('.map_sma .tw2gui_window_content_pane img').css({'width':'100%','height':'100%'});};
		if (fort == 'sredni') {
			wman.open('map_med nominimize noreload').addTab('Średni fort').setMiniTitle('średni fort').setResizeable('on');
			jQuery('.map_med .tw2gui_window_content_pane').append('<img src="'+med_fort_img+'" />');
			jQuery('.map_med .tw2gui_window_content_pane img').css({'width':'100%','height':'100%'});};
		if (fort == 'duzy') {
			wman.open('map_big nominimize noreload').addTab('Duży fort').setMiniTitle('duży fort').setResizeable('on');
			jQuery('.map_big .tw2gui_window_content_pane').append('<img src="'+big_fort_img+'" />');
			jQuery('.map_big .tw2gui_window_content_pane img').css({'width':'100%','height':'100%'});};
		};
		
		kanal_rss = function (kanal){
		if (kanal == 'ogolny') {
			wman.open('ogolny nominimize noreload').addTab('Informacje').setMiniTitle('Informacje').setResizeable('on');
			var url = 'http://dariuszszyndler.pl/wp/?json=1&callback=?';
			jQuery('.ogolny .tw2gui_window_content_pane').append('<div id="cont_ogolny"><a id="kanal_rss" href="javascript:void(0);">Pobierz informacje</a></div>');
			jQuery('.ogolny .tw2gui_window_content_pane div#cont_ogolny').css({'width':'100%','height':'100%','text-align':'center','overflow-y':'auto'});
			jQuery('#kanal_rss').ready(function() {
				jQuery('#cont_ogolny').empty();
				jQuery.getJSON(url, function(data) {
					//console.log(jQuery(data).find('posts'));
					jQuery.each(data.posts, function(postIndex, post) {
						//console.log(post.slug);
						html = '<div class="slug" style="width:100%">';
						html += '<hr />';
						html += '<sup style="float:left">' + post.date + '</sup>';
						html += '<h2 class="textart_title">' + post.slug + '</h2>';
						html += post.content;
						html += '</div>';
						jQuery('#cont_ogolny').append(html);
						jQuery('#cont_ogolny a').attr('target','_blank');
					});
				});
			});
			return false;
		}};
		
		var prawe_menu = [
		{'id':'lbmp0','tekst':'budynki','warst':'lbm'},
		{'id':'lbmp1','tekst':'eksport','warst':'lem'},
		{'id':'lbmp2','tekst':'info','warst':'lim'}];
		var dmbp = '';
		jQuery.each(prawe_menu, function() {
		dmbp += '<div style="display:block;position:relative;width:80px;height:20px;float:left;top:-30px;left:0px;background:url('+base_img+'bg_b1.png) no-repeat;font-size:0.9em;text-align:center" id="'+this['id']+'">';
		dmbp += '<a href="javascript:void(0)" onclick="javascript:hide(\''+this['warst']+'\')">'+this['tekst']+'</a>';
		dmbp += '</div>';
		});
		jQuery('#p_ext_menu').append(dmbp);
		
		$('pbmb').addEvents({ click:function(){ top_pm = $('p_ext_menu').getStyle('top'); if ( top_pm == '-50px'){ $('p_ext_menu').setStyle('top','0px'); } else { $('p_ext_menu').setStyle('top','-50px'); }}});
		$('lbmb').addEvents({ click:function(){ top_pm = $('l_ext_menu').getStyle('top'); if ( top_pm == '-60px'){ $('l_ext_menu').setStyle('top','0px'); } else { $('l_ext_menu').setStyle('top','-60px'); }}});
		
		// menu budynkow
		prawe_menu_skroty = [
		{'tytul':'Rusznikarz','img_src':'/images/items/right_arm/mini/deringer_accurate.png','link':'Trader.open(\'gunsmith\', Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Krawiec','img_src':'/images/items/body/mini/tuetue.png','link':'Trader.open(\'tailor\', Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'General Store','img_src':'/images/items/neck/mini/kerchief_blue.png','link':'Trader.open(\'general\', Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Hotel','img_src':'/images/items/right_arm/mini/pillow.png','link':'HotelWindow.open(Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Bank','img_src':'/images/items/yield/bag.png','link':'AjaxWindow.show(\'building_bank\',{town_id:Character.home_town.town_id},Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Kościół','img_src':'/images/items/neck/mini/cross_bronze.png','link':'ChurchWindow.open(Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Grabarz','img_src':'/images/items/yield/testament.png','link':'MorticianWindow.open(Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Ratusz','img_src':'/images/bank/city.png','link':'CityhallWindow.open(Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Saloon','img_src':'/images/items/yield/beer.png','link':'AjaxWindow.show(\'building_saloon\',{town_id:Character.home_town.town_id},Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Szeryf','img_src':'/images/items/yield/sheriffstar.png','link':'AjaxWindow.show(\'building_sheriff\',{town_id:Character.home_town.town_id},Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Targ','img_src':'/images/items/yield/stolen_goods.png','link':'MarketWindow.open(Character.home_town.town_id, 10);','layer':'lbm'},
		{'tytul':'Handlarz','img_src':'/images/itemtrader/haendler_btn.jpg','link':'Trader.open(\'item_trader\');','layer':'lbm'},
		{'tytul':'Idź do miasta','img_src':'/images/items/yield/flag.png','link':'AjaxWindow.show(\'fingerboard\',{town_id:Character.home_town.town_id},Character.home_town.town_id);','layer':'lbm'},
		{'tytul':'Profil','img_src':'/images/items/yield/photo.png','link':'AjaxWindow.show(\'profile\',{char_id:Character.playerId},Character.playerId);','layer':'lbm'},
		{'tytul':'Rzemiosło','img_src':'/images/items/recipe/recipe_smith.png','link':'CharacterWindow.open();CharacterWindow.showTab(\'crafting\');','layer':'lbm'},
		{'tytul':'Zaproszenia','img_src':'/images/items/yield/letter.png','link':'AjaxWindow.show(\'invitations\');','layer':'lbm'},
		{'tytul':'Eksport do TW-DB.info','img_src':ico_inw_twdb,'link':'wman.open(\'twdbi nominimize noreload\').addTab(\'Proszę czekać...\');jQuery.getScript(\'http://tw-db.info/cache/js/sDoImport_pl.js\');','layer':'lem'},
		{'tytul':'Eksport do westforts.com','img_src':ico_inw_wf,'link':'wman.open(\'wfi nominimize noreload\').addTab(\'Informacja\');jQuery(\'.wfi .tw2gui_window_content_pane\').append(\''+help_wf+'\');jQuery.getScript(\'http://www.westforts.com/js/import_userscript.js?'+new Date().getTime()+'\');','layer':'lem'},
		{'tytul':'Mapka małego fortu','img_src':sma_fort_ico,'link':'forty(\'maly\');','layer':'lem'},
		{'tytul':'Mapka średniego fortu','img_src':med_fort_ico,'link':'forty(\'sredni\');','layer':'lem'},
		{'tytul':'Mapka dużego fortu','img_src':big_fort_ico,'link':'forty(\'duzy\');','layer':'lem'},
		{'tytul':'Kanał informacyjny','img_src':'/images/items/yield/letter.png','link':'kanal_rss(\'ogolny\');','layer':'lim'}];
		
		var dlbm = '';
		var dlem = '';
		var dlim = '';
		jQuery.each(prawe_menu_skroty, function(index) {
			if(this['layer'] == 'lbm') {
				if(Character.home_town != null && index != 15 && index != 14){
					dlbm += '<div id="lbm_'+this['tytul']+'" style="float:left">';
					dlbm += '<a href="javascript:void(0);" onclick="javascript:'+this['link']+'"><img src="'+this['img_src']+'" style="width:44px; height:44px" title="<b>'+this['tytul']+'</b>" alt="'+this['tytul']+'" /></a></div>';
				} else if((Character.home_town == null) && (index == 11 || index == 13 || index == 15)) {
					dlbm += '<div id="lbm_'+this['tytul']+'" style="float:left">';
					dlbm += '<a href="javascript:void(0);" onclick="javascript:'+this['link']+'"><img src="'+this['img_src']+'" style="width:44px; height:44px" title="<b>'+this['tytul']+'</b>" alt="'+this['tytul']+'" /></a></div>';
				} else if(index == 14 && Character.profession_skill != null ) {
					dlbm += '<div id="lbm_'+this['tytul']+'" style="float:left">';
					dlbm += '<a href="javascript:void(0);" onclick="javascript:'+this['link']+'"><img src="'+this['img_src']+'" style="width:44px; height:44px" title="<b>'+this['tytul']+'</b>" alt="'+this['tytul']+'" /><div style="color:white; margin-left:10px; margin-top:-20px">'+Character.profession_skill+'</div></a></div>';
				}
			} else if(this['layer'] == 'lem') {
				dlem += '<div id="lem_'+this['tytul']+'" style="float:left">';
				dlem += '<a href="javascript:void(0);" onclick="javascript:'+this['link']+'"><img src="'+this['img_src']+'" style="width:44px; height:44px" title="<b>'+this['tytul']+'</b>" alt="'+this['tytul']+'" /></a></div>';
			} else if(this['layer'] == 'lim') {
				dlim += '<div id="lim_'+this['tytul']+'" style="float:left">';
				dlim += '<a href="javascript:void(0);" onclick="javascript:'+this['link']+'"><img src="'+this['img_src']+'" style="width:44px; height:44px" title="<b>'+this['tytul']+'</b>" alt="'+this['tytul']+'" /></a></div>';
			}
		});
		
		jQuery('#lbm').append(dlbm);
		jQuery('#lem').append(dlem);
		jQuery('#lim').append(dlim).append('<div id="lim0" style="float:left;margin:5px;text-align:center"> w przygotowaniu<br />wersja: '+werTWFS+' z dnia: '+dateTWFS+'</div>');
		
		// przeniesienie prac
		$('workbar_left').setStyles({'left':'0px','float':'left','width':'auto','height':'auto','position':'relative'});
		$('workbar_left').style.setProperty('margin-top', '0px', 'important');
		$('workbar_left').style.setProperty('top', '-12px', 'important');
		$('workbar_left').style.setProperty('z-index', '1', 'important');
		$$('.workbar_top').setStyles({'height':'auto'});
		$('workbar_right').setStyles({'left':'0px','float':'left','width':'auto','height':'auto','position':'relative'});
		$('workbar_right').style.setProperty('margin-top', '0px', 'important');
		$('workbar_right').style.setProperty('top', '-12px', 'important');
		$('workbar_right').style.setProperty('z-index', '1', 'important');
		$$(['wb_task_0','wb_task_1','wb_task_2','wb_task_3','wb_task_4','wb_task_5','wb_task_6','wb_task_7']).setStyles({'margin-left':'-5px','margin-right':'0px','float':'left','opacity':'0.8','filter':'alpha(opacity=80)'});
		$$(['wb_task_0','wb_task_1','wb_task_2','wb_task_3','wb_task_4','wb_task_5','wb_task_6','wb_task_7']).setStyles({'background':'url('+base_img+'/workbar_item_background.png) no-repeat 0px 32px'}); // podmiana grafiki pod wykonywanymi pracami
		// end przeniesienie prac
	});
})